package fileby.model.impl.sources.impl;

import fileby.model.impl.sources.FileItem;
import fileby.core.SourceType;
import fileby.util.properties.PropertyBundle;
import fileby.core.IDisplayableFileSource;
import fileby.util.properties.IPropertyBundleProvider;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Jacob
 */
class ComputerSource extends AbstractFileSource {

    private IPropertyBundleProvider propertyBundleProvider;

    public ComputerSource(IPropertyBundleProvider propertyBundleProvider) {
        this.propertyBundleProvider = propertyBundleProvider;
        sourceType = SourceType.COMPUTER;
        for (File f : File.listRoots()) {
            if (f.isDirectory()) {
                files.add(new FileItem(f));
            }
        }
        try {
            name = java.net.InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        PropertyBundle p = this.propertyBundleProvider.create(this.getClass());
        icon = p.getIcon("computerIcon.icon");
    }

    public String getAbsolutePath() {
        return sourceType.toString();
    }

    public IDisplayableFileSource getParent() {
        return null;
    }

    @Override
    public boolean addFiles(List<File> fileList, int action) throws IOException {
        return false; //No need to update
    }

    public void updateContent() {
        List<File> updatedFiles = new ArrayList();
        for (File f : File.listRoots()) {
            if (f.isDirectory()) {
                updatedFiles.add(f);
            }
        }
        syncList(updatedFiles);
        sortList();
    }
}
